package com.krahets88.stack;

import java.util.Stack;


public class Question232 {

}

/**
 * 思路：
 * 1. 出栈的时候用2出
 * 2，进栈的时候进入到1内
 * 3. 如果2内的元素为空，直接将1内所有的元素移动到2
 */
class MyQueue {
    Stack<Integer> stack1;
    Stack<Integer> stack2;

    public MyQueue() {
        stack1 = new Stack<>();
        stack2 = new Stack<>();
    }

    public void push(int x) {
        stack1.push(x);
    }

    public int pop() {
        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.pop();
    }

    public int peek() {
        if (stack2.isEmpty()) {
            while (!stack1.isEmpty()){
                stack2.push(stack1.pop());
            }
        }
        return stack2.lastElement();
    }

    public boolean empty() {
        return stack2.isEmpty() && stack1.isEmpty();
    }
}